package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 目标：
 *
 * @author Ashely
 * @date 2024/6/8 17:35
 */
@RestController("adminCategoryController")
@RequestMapping("/admin/category")
@Api(tags = "菜品分类接口")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    @ApiOperation("新增菜品分类接口")
    public Result add(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增菜品分类：{}", categoryDTO);
        categoryService.add(categoryDTO);
        return Result.success();

    }

    @GetMapping("/page")
    @ApiOperation("分页查询菜品分类接口")
    public Result pageQuery(CategoryPageQueryDTO cpqd, String name, Integer type) {
        PageResult pageResult = categoryService.pageQuery(cpqd);
        return Result.success(pageResult);
    }

    @DeleteMapping
    @ApiOperation("删除菜品分类接口")
    public Result deleteById(Long id) {
        log.info("删除菜品分类：{}", id);
        categoryService.deleteById(id);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用菜品分类接口")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        log.info("启用禁用菜品分类：{}", id);
        categoryService.startOrStop(status, id);
        return Result.success();

    }
    @PutMapping
    @ApiOperation("修改菜品分类接口")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();

    }
    @GetMapping("/list")
    @ApiOperation("根据类型查询菜品分类接口")
    public Result list(Integer type){
        log.info("根据类型查询菜品分类：{}", type);
        List<Category> list = categoryService.findByType(type);
        return Result.success(list);
    }
}
